package me.magicall.myblog.util;

import me.magicall.util.Utils;

public interface UrlPatternRule {

	String MODEL_NAME = "/{modelName:\\w+}";
	String ID = "/{id:\\d+}";
	String MAYBE_ID = "/{id:\\d*}";
	String IDS = "/{ids:\\d+}";
	String IDS_LIST = "/{ids:[\\d+,]+}";
	String IDS_RANGE = "/{ids:\\d+~\\d+}";
	String PAGE = "/{page:\\d+}";

	public enum UrlPatternPart {

		MODEL_NAME("modelName", "\\w+"), //
		ID("id", "\\d+"), //
		MAYBE_ID("id", "\\d*"), //
		IDS_LIST("ids", "\\d+[,\\d]*"), //
		IDS_RANGE("ids", "\\d+~\\d+"), //
		OP("", "\\w+"), //
		;
		private UrlPatternPart(final String paramName, final String regex) {
			this.paramName = paramName;
			this.regex = regex;
			if (Utils.STR.isEmpty(paramName)) {
				urlPatternRule = "/{" + regex + "}";
			} else {
				urlPatternRule = "/{" + paramName + ":" + regex + "}";
			}
		}

		public final String urlPatternRule;
		public final String paramName;
		public final String regex;
	}

}
